/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sevent.controller;

import com.sevent.service.UserService;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.WebUtils;

/**
 * 
 * @author enriquer
 */
@Controller()
public class UserController {

    private static final Log log = LogFactory.getLog(UserController.class);
    //
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/signUp.htm", method = RequestMethod.GET)
    public ModelAndView signUp() {
        return new ModelAndView("signUp");
    }

    @RequestMapping(value = "/doSignUp.htm", method = RequestMethod.POST)
    public ModelAndView doSignUp(HttpServletRequest request) {

        try {
            Map<String, Object> userData = WebUtils.getParametersStartingWith(request, null);
            log.info(userData);
            userService.addUser(userData);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
        return new ModelAndView("signUp");
    }
}
